home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / c / cc02.zip / CPIO.C < prev    next >
Text File  |  1985-08-28  |  736b  |  41 lines

  1. /* cpio: copy input to output */
  2.  
  3. #define  BUFSIZE  512       /* best size for IBM PC/XT/AT */
  4. #define  CMASK      '\377'   /* for making char's > 0 */
  5.  
  6. main()
  7. {
  8.       char  buf[BUFSIZE];
  9.       int   n;
  10.  
  11.       while ((n = read(0, buf, BUFSIZE)) > 0)
  12.      write(1, buf, n);
  13.       exit(0);
  14. }
  15.  
  16.  
  17. getchars()  /* unbuffered single character input */
  18. {
  19.       char  c;
  20.  
  21.       return((read(0, &c, 1) > 0) ? c & CMASK : EOF);
  22. }
  23.  
  24.  
  25. getcharb()  /* buffered version */
  26. {
  27.       static   char  buf[BUFSIZE];
  28.       static   char  *bufp = buf;
  29.       static   int   n = 0;
  30.  
  31.       if (n == 0) {  /* buffer is empty */
  32.      n = read(0, buf, BUFSIZE);
  33.      bufp = buf;
  34.       }
  35.       return((-n >= 0) ? *bufp++ & CMASK : EOF);
  36. }
  37.  
  38.  
  39.  
  40.  
  41.